package com.cn;

import com.cn.common.ServerThread;

import java.util.concurrent.*;

public class TestLinkBlockingQueue extends ServerThread {

    private LinkedBlockingQueue<String> list = new LinkedBlockingQueue<>();

    @Override
    public String getServiceName() {
        return TestLinkBlockingQueue.class.getSimpleName();
    }

    public void test(String result) {
        System.out.println("result:" + result);
    }

    public void put(String a) {
        try {
            this.list.put(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while (!isStopped()) {
            try {
                this.waitForRunning(1000);
                System.out.println("执行来了");
                String result = list.take();
                test(result);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
